<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>首页--layui后台管理模板 2.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="../../static/resources/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="../../static/resources/css/public.css" media="all"/>
</head>
<body class="childrenBody">
<blockquote class="layui-elem-quote layui-bg-green">
    <div id="nowTime"></div>
</blockquote>
</div>
<div class="layui-row layui-col-space10">
    <div class="layui-col-lg6 layui-col-md6">
        <blockquote class="layui-elem-quote title">最新公告 <i class="layui-icon layui-red">&#xe756;</i></blockquote>
        <table class="layui-table mag0" lay-skin="line" >
            <colgroup>
                <col>
                <col width="110">
            </colgroup>
            <tbody class="hot_news"></tbody>
        </table>
    </div>
    <div class="layui-col-lg6 layui-col-md6">
        <blockquote class="layui-elem-quote title">库存预警 <i class="layui-icon layui-red">&#xe702;</i></blockquote>
        <table class="layui-table mag0" lay-skin="line" >
            <colgroup>
                <col>
                <col width="110">
            </colgroup>
            <tbody class="goods_danger"></tbody>
        </table>
    </div>
    <!--文章详情弹窗开始-->
    <div id="noticeDetailDiv" style="display: none; padding: 20px">
        <h2 id="view_title" align="center"></h2>
        <hr>
        <div style="text-align: right; color: #393D49">
            发布人:<span id="view_opername"></span> <span
                style="display: inline-block; width: 20px"></span> 发布时间:<span
                id="view_createtime"></span>
        </div>
        <hr>
        <div id="view_content" style="font-size: 14px;"></div>
    </div>
    <!--文章详情弹窗结束-->
</div>
<div class="layui-row layui-col-space10">
    <div class="layui-col-lg6 layui-col-md6">
        <blockquote class="layui-elem-quote title">我的任务进度 <i class="layui-icon layui-red">&#xe60e;</i></blockquote>
        <table class="layui-table mag0" lay-skin="line" >
            <colgroup>
                <col>
                <col width="110">
            </colgroup>
            <tbody class="task_process"></tbody>
        </table>
    </div>
    <div class="layui-col-lg6 layui-col-md6">
        <blockquote class="layui-elem-quote title">我的待办任务 <i class="layui-icon layui-red">&#xe667;</i></blockquote>
        <table class="layui-table mag0" lay-skin="line" >
            <colgroup>
                <col>
                <col width="110">
            </colgroup>
            <tbody class="wait_task"></tbody>
        </table>
    </div>
</div>
<script type="text/javascript" src="/resources/layui/layui.js"></script>
<script type="text/javascript">
	//获取系统时间
	var newDate = '';
	getLangDate();
	//值小于10时，在前面补0
	function dateFilter(date){
		if(date < 10){return "0"+date;}
		return date;
	}
	function getLangDate(){
		var dateObj = new Date(); //表示当前系统时间的Date对象
		var year = dateObj.getFullYear(); //当前系统时间的完整年份值
		var month = dateObj.getMonth()+1; //当前系统时间的月份值
		var date = dateObj.getDate(); //当前系统时间的月份中的日
		var day = dateObj.getDay(); //当前系统时间中的星期值
		var weeks = ["星期日","星期一","星期二","星期三","星期四","星期五","星期六"];
		var week = weeks[day]; //根据星期值，从数组中获取对应的星期字符串
		var hour = dateObj.getHours(); //当前系统时间的小时值
		var minute = dateObj.getMinutes(); //当前系统时间的分钟值
		var second = dateObj.getSeconds(); //当前系统时间的秒钟值
		var timeValue = "" +((hour >= 12) ? (hour >= 18) ? "晚上" : "下午" : "上午" ); //当前时间属于上午、晚上还是下午
		newDate = dateFilter(year)+"年"+dateFilter(month)+"月"+dateFilter(date)+"日 "+" "+dateFilter(hour)+":"+dateFilter(minute)+":"+dateFilter(second);
		document.getElementById("nowTime").innerHTML = timeValue+"好！ 欢迎使用 Y·F仓储管理系统,当前时间为： "+newDate+"　"+week;
		setTimeout("getLangDate()",1000);
	}


	layui.use(['form','element','layer','jquery'],function() {
		var form = layui.form,
				layer = parent.layer === undefined ? layui.layer : top.layer,
				element = layui.element;
		$ = layui.jquery;
		//上次登录时间【此处应该从接口获取，实际使用中请自行更换】
		$(".loginTime").html(newDate.split("日")[0] + "日</br>" + newDate.split("日")[1]);
		//icon动画
		$(".panel a").hover(function () {
			$(this).find(".layui-anim").addClass("layui-anim-scaleSpring");
		}, function () {
			$(this).find(".layui-anim").removeClass("layui-anim-scaleSpring");
		})
		$(".panel a").click(function () {
			parent.addTab($(this));
		})
		//最新文章列表
		$.get("/sys/notice/loadNotice", function (data) {
			var hotNewsHtml = '';
			var length = 5;
			if(data.data.length<5){
			    length = data.data.length;
            }
			for (var i = 0; i < length; i++) {
				hotNewsHtml += '<tr ondblclick="showNoticeDetail('+data.data[i].id+')">'
						+ '<td align="left"><a href="javascript:;"> ' + data.data[i].title + '</a></td>'
						+ '<td>' + data.data[i].createtime.substring(0, 10) + '</td>'
						+ '</tr>';
			}
			$(".hot_news").html(hotNewsHtml);
			$(".userAll span").text(data.length);
		})
        //库存预警
        $.get("/bus/goods/loadDangerGoods", function (data) {
            if(data.length>0){
                var dangerGoods = '';
                var length = 5;
                if(data.length<5){
                    length = data.length;
                }
                for (var i = 0; i < length; i++) {
                    dangerGoods += '<tr>'
                        + '<td align="left"><a href="javascript:;"> ' + data[i].goodsname + '</a></td>'
                        + '<td>' + data[i].num + '/'+data[i].goodspackage+'</td>'
                        + '</tr>';
                }
                $(".goods_danger").html(dangerGoods);
                $(".userAll span").text(data.length);
            }else{
                $(".goods_danger").html('<td align="center" style="color:darkblue"><a href="javascript:;">无库存预警商品</a></td>');
            }
        })
        //我的任务进度
        $.get("/sys/leavebill/loadLeavelbill", function (result) {
            if(result.data.length>0){
                var dangerGoods = '';
                var length = 5;
                if(result.data.length<5){
                    length = result.data.length;
                }
                for (var i = 0; i < length; i++) {
                    dangerGoods += '<tr>'
                        + '<td align="left" width="300px"><a href="javascript:;"> ' + result.data[i].title + '</a></td>'
                        + '<td align="left" width="200px">'+ result.data[i].leavetime.substring(0, 10) +'</a></td>'
                        + '<td align="center">' + result.data[i].stateString +'</td>'
                        + '</tr>';
                }
                $(".task_process").html(dangerGoods);
                $(".userAll span").text(result.length);
            }else{
                $(".task_process").html('<td align="center" style="color:darkblue"><a href="javascript:;">无任务</a></td>');
            }
        })
        //我的待办任务
        $.get("/sys/task/getDeskTopWaitTask", function (result) {
            if(result.data.length>0){
                var dangerGoods = '';
                var length = 5;
                if(result.data.length<5){
                    length = result.data.length;
                }
                for (var i = 0; i < length; i++) {
                    dangerGoods += '<tr>'
                        + '<td align="left" width="300px"><a href="javascript:;"> ' + result.data[i].title + '</a></td>'
                        + '<td align="left" width="100px">'+ result.data[i].leavetime.substring(0, 10) +'</a></td>'
                        + '<td align="center">' + result.data[i].contentString +'</td>'
                        + '</tr>';
                }
                $(".wait_task").html(dangerGoods);
                $(".userAll span").text(result.length);
            }else{
                $(".wait_task").html('<td align="center" style="color:darkblue"><a href="javascript:;">无任务</a></td>');
            }
        })

		//用户数量
		$.get("/resources/json/userList.json", function (data) {
			$(".userAll span").text(data.count);
		})

		//外部图标
		$.get(iconUrl, function (data) {
			$(".outIcons span").text(data.split(".icon-").length - 1);
		})

	})
    function showNoticeDetail(id){
        $.post("/sys/notice/getNoticeByid",{id:id},function(data){
            layer.open({
                type: 1,
                title: '查看公告',
                content: $("#noticeDetailDiv"),
                area: ['600px', '500px'],
                success: function (index) {
                    $("#view_title").text(data.data.title);
                    $("#view_createtime").text(data.data.createtime);
                    $("#view_opername").text(data.data.opername);
                    $("#view_content").html(data.data.content);
                }
            });
        })

    }
</script>
</body>
</html>